import { usePermission } from '@/hooks/usePermission'

export const hasPermission = {
  mounted(el, binding) {
    if (!binding.value) return
    const { action, effect } = binding.value
    const { hasPermission } = usePermission()
    if (!hasPermission(action)) {
      if (effect === 'disabled') {
        el.disabled = true
        el.style['disabled'] = 'disabled'
        el.classList.add('n-button--disabled')
      } else {
        el.remove()
      }
    }
  },
}
